﻿using MediatR;
using SY.BasicData.Api.Read.Applications.Cultivation.Command;
using SY.BasicData.Domain.Cultivation;
using SY.BasicData.ErrorCode;
using SY.BasicData.Infrastructures;

namespace SY.BasicData.Api.Read.Applications.Cultivation.CommandHandler
{
    public class ImmunityDetailCommandHandler : IRequestHandler<ImmunityDetailCommand, ApiResult<ImmunityModel>>
    {
        private readonly IBaseRepository<ImmunityModel> ImmunityRepository;

        public ImmunityDetailCommandHandler(IBaseRepository<ImmunityModel> immunityRepository)
        {
            ImmunityRepository = immunityRepository;
        }

        public Task<ApiResult<ImmunityModel>> Handle(ImmunityDetailCommand request, CancellationToken cancellationToken)
        {
            ApiResult<ImmunityModel> result = new ApiResult<ImmunityModel>();
            result.Code = ApiEnum.Success;
            result.Message = "养殖信息明细成功";
            var list = ImmunityRepository.GetAll().Where(x => x.Batch == request.Batch).FirstOrDefault();
            if (list == null)
            {
                result.Code = ApiEnum.Fail;
                result.Message = "不存在此信息";
                return Task.FromResult(result);
            }
            result.Data = list;
           return Task.FromResult(result);

        }
    }
}
